﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kira.Compiler.Bods
{
    [XmlElementMapping("DIDatabaseTableTarget")]
    public class DIDatabaseTableTarget : BodsTransform
    {
        public String DatastoreName
        {
            get
            {
                return this.GetAttrbuteValue("datastoreName");
            }
        }

        public String OwnerName
        {
            get
            {
                return this.GetAttrbuteValue("ownerName");
            }
        }

        public String TableName
        {
            get
            {
                return this.GetAttrbuteValue("tableName");
            }
        }

        public String InputName
        {
            get
            {
                return this.GetElement("DIInputView").GetAttrbuteValue("name");
            }
        }

        public override IEnumerable<string> InputNames
        {
            get { return new String[] { this.InputName }; }
        }

        public override IEnumerable<string> OutputNames
        {
            get { return new String[] { }; }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(GetComments("DIDatabaseTableTarget"));
            sb.Append("INSERT INTO ");
            if (!String.IsNullOrWhiteSpace(OwnerName))
            {
                sb.Append(OwnerName).Append(".");
            }
            sb.Append(TableName).Append(" SELECT * FROM ").AppendLine(InputName);
            return sb.ToString();
        }
    }
}
